/* Copyright Statement:
 *
 * This software/firmware and related documentation ("AutoChips Software") are
 * protected under relevant copyright laws. The information contained herein is
 * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
 * the prior written permission of AutoChips inc. and/or its licensors, any
 * reproduction, modification, use or disclosure of AutoChips Software, and
 * information contained herein, in whole or in part, shall be strictly
 * prohibited.
 *
 * AutoChips Inc. (C) 2022. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
 * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
 * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
 * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
 * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
 * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
 * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
 * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
 */

/*!
 * @file eep_drv.c
 * version: V2.1.7 EEP
 * @brief This file provides EEP integration functions.
 *
 */

/* ===========================================  Includes  =========================================== */
#include "eep_drv.h"
#include <string.h>
/* ============================================  Define  ============================================ */
/* EEP group size define rule:
   1. Total EEP size (Byte) = EEP SRAM size which base address is EepRamBaseAddr
   2. The min EEP_GROUP_SIZE = EEP_SIZE (word) * 2 * EepFlashMinProByteNum
   3. EEP_FLASH_SIZE = EEP_GROUP_SIZE * Total group
*/

/* EEP operate group flag */
#define EEP_GROUP_FLAG_VALUE            (0x00000000U)

/* EEP total group number */
#define EEP_GROUPS_NUM                  (4U)

/* EEP FLASH max program unit size */
#define EEP_FLASH_MAX_UNIT_SIZE         (32U)
/* ===========================================  Typedef  ============================================ */

/* ====================================  Functions declaration  ===================================== */
extern void Eep_Flash_LockCtrl(void);
extern Eep_StatusType Eep_Flash_UnlockCtrl(void);
extern Eep_StatusType Eep_Flash_EraseGroup(uint32_t Addr, uint32_t Size);
extern Eep_StatusType Eep_Flash_VerifyGroup(uint32_t Addr, uint32_t Size);
extern Eep_StatusType Eep_Flash_Program(uint32_t Addr, uint32_t Size, const uint8_t *Data);
extern Eep_StatusType Eep_Flash_PreInitCheck(uint32_t RamAddr, uint32_t FlashAddr);
extern Eep_StatusType Eep_Flash_CheckBusy(void);

/* ==========================================  Variables  =========================================== */
static uint16_t EepSize = 4096U;
static uint32_t EepRamBaseAddr = 0x14000000U;
static uint32_t EepFlashBaseAddr = 0x1000000U;
static uint32_t EepGroupSize = 16 * 1024U;
static uint32_t EepFlashMinProByteNum = 8U;
static uint32_t EepFlashDateByteNum = 0U;

static volatile uint32_t CurFlashOperatAddr = 0U;
static volatile uint16_t CurGroup = 0U;
static volatile uint16_t LastGroup = 0U;
static uint32_t EepGroupFlag[EEP_FLASH_MAX_UNIT_SIZE / 4U] = {0U};
static uint32_t EepGroupAddr[EEP_GROUPS_NUM][2U] = {0U};

Eep_CallbackType g_eepCallback = 0U;
/* ======================================  Functions define  ======================================== */
/*!
 * @brief write data to FLASH, the Flash low 32-bit saved EEP address
 *
 * @param[in] flashAddr: write FLASH start address
 * @param[in] eepAddr: EEP address
 * @param[in] data: data pointer
 * @param[in] size: data byte number
 * @param[in] mode: 0: not write all sram data to FLASH, 1: write all sram data to FLASH
 * @return EEP operate status
 */
static Eep_StatusType WriteDataToDflash(volatile uint32_t *FlashAddr, uint32_t EepAddr,
                                      const uint8_t *Data, uint16_t Size, uint8_t Mode)
{
    Eep_StatusType Ret = EEP_SUCCESS;
    uint8_t NewCombineData[EEP_FLASH_MAX_UNIT_SIZE] = {0};
    uint8_t ByteWidth;
    uint16_t i = 0U;
    uint16_t TempSize = 0U;

    ByteWidth = 2U;

    while ((Size > 0U) && (EEP_SUCCESS == Ret))
    {
        /*Filled EEP address to array newCombineData */
        for (i = 0U; i < ByteWidth; i++)
        {
            NewCombineData[i] = (EepAddr >> (i * 8U)) & 0xFFU;
        }
        TempSize = EepFlashDateByteNum;
        if (Size < EepFlashDateByteNum)
        {
            TempSize = Size;
        }
        for (i = 0U; i < TempSize; i++)
        {
            NewCombineData[i + ByteWidth] = Data[i];
        }

        for (i = TempSize; i < EepFlashDateByteNum; i++)
        {
            if ((EepAddr + i) < (EepSize + EepRamBaseAddr))
            {
                NewCombineData[i + ByteWidth] = *(uint8_t *)(EepAddr + i);
            }
            else
            {
                NewCombineData[i + ByteWidth] = 0xFFU;
            }
        }

        if (1U == Mode)
        {
            for (i = 0U; i < EepFlashDateByteNum; i++)
            {
                if (0xFF != NewCombineData[i + ByteWidth])
                {
                    break;
                }
            }
        }
        if ((i < EepFlashDateByteNum) || (0U == Mode))
        {
            Ret = Eep_Flash_Program(*FlashAddr, EepFlashMinProByteNum, (uint8_t *)NewCombineData);
            *FlashAddr += EepFlashMinProByteNum;
        }

        Size -= TempSize;
        Data += TempSize;
        EepAddr += TempSize;
    }

    return Ret;
}

/*!
 * @brief look for the first data which is not 0xFFFFFFFF form end to start address
 *
 * @param[in] endAddr: end address
 * @param[in] validDataAddr: valid data start address
 * @return none
 */
static void GetValidDataStartAddr(uint8_t Group, volatile uint32_t *GroupOperateAddr)
{
    uint32_t i;
    uint32_t TempSize = (EepGroupSize / EepFlashMinProByteNum) - 1U;
    uint32_t TempAddr, Addr = 0U;
    uint32_t TempGroupEndAddr;

    TempGroupEndAddr = EepGroupAddr[Group][1U] - EepFlashMinProByteNum;
    *GroupOperateAddr = EepGroupAddr[Group][0U];
    for (i = 0U; i < TempSize; i++)
    {
        TempAddr = TempGroupEndAddr - (i + 1U) * EepFlashMinProByteNum;
        /* Check address is not 0xFFFFFFFF */
        Addr = (*((uint32_t *)(TempAddr)) << 16) >> 16;
        if (0xFFFFU != Addr)
        {
            *GroupOperateAddr = TempAddr + EepFlashMinProByteNum;
            break;
        }
    }
}

/*!
 * @brief get the flag value of operate of current group
 *
 * @param[in] group: EEP group index
 * @return the flag value
 */
static uint32_t GetEepGroupFlagVal(uint16_t Group)
{
    return (*(uint32_t *)(EepGroupAddr[Group][1U] - EepFlashMinProByteNum));
}

/*!
 * @brief check the current group index and caculate the count of the group flag
 *
 * @param[out] index: group index
 * @return the count of the group flag
 */
static uint8_t CheckOperateGroup(uint8_t *Index)
{
    uint8_t Cnt  = 0U;
    uint16_t i;

    for (i = 0U; i < EEP_GROUPS_NUM; i++)
    {
        if (EEP_GROUP_FLAG_VALUE == GetEepGroupFlagVal(i))
        {
            Cnt++;
            *Index = i;
        }
    }

    return Cnt;
}

/*!
 * @brief Load flash data to RAM
 *
 * @param[in] group: EEP group index
 * @param[in] operateAddr: EEP group operate address
 * @return EEP operate status
 */
static Eep_StatusType LoadFlashDataToSram(uint8_t Group, uint32_t OperateAddr)
{
    uint32_t i, j, Addr = 0U;
    uint32_t Temp = 0U;
    Eep_StatusType Ret = EEP_SUCCESS;

    for (i = EepGroupAddr[Group][0U]; i < OperateAddr; i += 4)
    {
        for (j = 0U; j < 2; j++)
        {
            Temp = *(uint32_t *)(i);
            Temp = (Temp << 16) >> 16;
            /* maybe the temp is 0xFFFF */
            if ((Temp >= (EepRamBaseAddr & 0xffff)) && (Temp < (EepRamBaseAddr + (EepSize) & 0xffff)))
            {
                Addr = ((EepRamBaseAddr >> 16) << 16) + Temp;
                *(uint8_t *)(Addr + j) = *(uint8_t *)(i + 2U + j);
            }
        }
    }

    return Ret;
}
/*!
 * @brief Load EEP data to SRAM from EEP group
 *
 * @param[in] curGroupOperateAddr: current group flash operate address
 * @param[in] lastGroupOperateAddr: last group flash operate address
 * @return EEP operate status
 */
static Eep_StatusType SortEepDataToSram(uint32_t CurGroupOperateAddr, uint32_t LastGroupOperateAddr)
{
    Eep_StatusType Ret = EEP_SUCCESS;
    /*
        1. Flash min width 64, 32-bit address + 32-bit data(AC784x)
        2. Flash min width 32, 32-bit address + 32-bit data(AC70x or AC781x)
        3. Flash min width 128, 32-bit address + 96-bit data(AC787x)
    */
    memset((char *)EepRamBaseAddr, 0xff, EepSize);

    Ret = LoadFlashDataToSram(LastGroup, LastGroupOperateAddr);

    if (EEP_SUCCESS == Ret)
    {
        Ret = LoadFlashDataToSram(CurGroup, CurGroupOperateAddr);
    }

    return Ret;
}

/*!
 * @brief update EEP group index and complete data copy
 *
 * @param[in] none
 * @return EEP operate status
 */
static Eep_StatusType UpdateOperateAddr(void)
{
    Eep_StatusType Ret = EEP_SUCCESS;
    uint8_t Index = 0U;
    uint8_t Cnt;
    uint32_t LastGroupOperateAddr = 0U;
    uint32_t TempAddr = 0U;
    uint32_t TmpCurFlashOperatAddr;

    Cnt = CheckOperateGroup(&Index);
    switch (Cnt)
    {
    case 0U:/* First used eep write operate flag in the first group */
        Ret = Eep_Flash_Program(EepGroupAddr[0U][1U] - EepFlashMinProByteNum,
                                EepFlashMinProByteNum, (uint8_t *)EepGroupFlag);
        CurGroup = 0U;
        LastGroup = EEP_GROUPS_NUM - 1U;
        break;

    case 1U:
        if (0U == Index)
        {
            CurGroup = 0U;
            LastGroup = EEP_GROUPS_NUM - 1U;
        }
        else
        {
            CurGroup = Index;
            LastGroup = Index - 1U;
        }
        break;

    case 2U:
        /* indicate copy fail last time from the previous group to the next group
          then it should copy again and erase the previous group, cnt=2 so index never = 1 at least
        */
        if ((EEP_GROUP_FLAG_VALUE == GetEepGroupFlagVal(Index - 1U)) &&
                (EEP_GROUP_FLAG_VALUE == GetEepGroupFlagVal(Index)))
        {
            CurGroup = Index;
            LastGroup = Index - 1U;

        }/*indicate copy fail last time from the lasst group to the first group
               then it should copy again and erase the last group, index = the last group
            */
        else if
        ((EEP_GROUP_FLAG_VALUE == GetEepGroupFlagVal(0U)) &&
                (EEP_GROUP_FLAG_VALUE  == GetEepGroupFlagVal(Index)))
        {
            CurGroup = 0U;
            LastGroup = Index;
        }
        else
        {
            Ret = EEP_OTHER_ERROR;
        }
        break;

    default:
        Ret = EEP_OTHER_ERROR;
        break;
    }

    GetValidDataStartAddr(CurGroup , &CurFlashOperatAddr);
    GetValidDataStartAddr(LastGroup , &LastGroupOperateAddr);
    if (EEP_SUCCESS == Ret)
    {
        Ret = SortEepDataToSram(CurFlashOperatAddr, LastGroupOperateAddr);
    }

    if ((EEP_SUCCESS == Ret) && (2U == Cnt))
    {
        TmpCurFlashOperatAddr = CurFlashOperatAddr;
        if (EepGroupAddr[CurGroup][0U] == TmpCurFlashOperatAddr)
        {
            TempAddr = EepRamBaseAddr;
        }
        else
        {
            TempAddr =*(uint32_t *)(CurFlashOperatAddr - EepFlashMinProByteNum);
            TempAddr = ((TempAddr << 16) >> 16) + ((EepRamBaseAddr >> 16) << 16);
        }

        Ret = WriteDataToDflash(&CurFlashOperatAddr, TempAddr, (uint8_t *)TempAddr,
                                EepRamBaseAddr + EepSize - TempAddr, 1U);
        if (EEP_SUCCESS == Ret)
        {
            /* erase last group */
            Ret = Eep_Flash_EraseGroup(EepGroupAddr[LastGroup][0U], EepGroupSize);
        }
    }

    return Ret;
}

/*!
 * @brief EEP Write
 *
 * @param[in] addr: EEP address
 * @param[in] data: data buffer pointer
 * @param[in] size: write byte number
 * @return EEP operate status
 */
static Eep_StatusType Eep_WriteExt(uint32_t Addr, const uint8_t *Data, uint16_t Size)
{
    Eep_StatusType Ret = EEP_SUCCESS;
    uint32_t LeftSize = 0U;
    uint16_t TempSize = 0U;
    uint32_t TmpCurFlashOperatAddr;

    TmpCurFlashOperatAddr = CurFlashOperatAddr;
    LeftSize = (EepGroupAddr[CurGroup][1U] - EepFlashMinProByteNum - TmpCurFlashOperatAddr) / EepFlashMinProByteNum;
    /*
        check write data not enough one FLASH min write unit size - 4(EEP addr)
        According to the code, size is never more than EepFlashDateByteNum
    */
    TempSize = (uint16_t)(Size / EepFlashDateByteNum);
    if (TempSize == 0U)
    {
        TempSize = 1U;
    }

    /* check space is enough, every word combine with write address will use 8 FLASH address */
    if (LeftSize >= TempSize)
    {
        /* has enough space */
        Ret = WriteDataToDflash(&CurFlashOperatAddr, Addr, Data, Size, 0U);
    }
    else
    {
        /* verify whether next eep group is eraseed, normally
           the following erase step will not need to be executed
        */
        Ret = Eep_Flash_VerifyGroup(EepGroupAddr[(CurGroup + 1U) % EEP_GROUPS_NUM][0U], EepGroupSize);
        if (EEP_SUCCESS != Ret)
        {
            Ret = Eep_Flash_EraseGroup(EepGroupAddr[(CurGroup + 1U) % EEP_GROUPS_NUM][0U], EepGroupSize);
        }
        if (EEP_SUCCESS != Ret)
        {
            return Ret;
        }
        /* write group operate flag (64-bit 0) to the next group*/
        Ret = Eep_Flash_Program(EepGroupAddr[(CurGroup + 1U) % EEP_GROUPS_NUM][1U] - EepFlashMinProByteNum,
                                EepFlashMinProByteNum, (uint8_t *)EepGroupFlag);
        /* write all the SRAM data to next group */
        if (EEP_SUCCESS == Ret)
        {
            CurFlashOperatAddr = EepGroupAddr[(CurGroup + 1U) % EEP_GROUPS_NUM][0U];
            /* write data to the next group */
            Ret = WriteDataToDflash(&CurFlashOperatAddr, EepRamBaseAddr, (uint8_t *)EepRamBaseAddr, EepSize, 1U);
        }
        /* copy current group data to next group */
        if (EEP_SUCCESS == Ret)
        {
            LastGroup = CurGroup;
            CurGroup = (CurGroup + 1U) % EEP_GROUPS_NUM;
            if (EEP_SUCCESS == Ret)
            {
                Ret = Eep_Flash_EraseGroup(EepGroupAddr[LastGroup][0U], EepGroupSize);
            }
        }
    }

    return Ret;
}

/*!
 * @brief EEP Write
 *
 * @param[in] addr: EEP address
 * @param[in] data: data buffer pointer
 * @param[in] size: the size of write data(uint is byte)
 * @return EEP operate status
 *  0U: Successfully
 *  1U: FLASH status error, can Check error by register 0x40002000U
 *  2U: Input parameter error
 *  3U: timeout
 *  4U: other error
 */
Eep_StatusType Eep_Hal_Write(uint32_t Addr, const uint8_t *Data, uint16_t Size)
{
    Eep_StatusType Ret = EEP_SUCCESS;
    uint8_t i = 0U;
    uint32_t TempAddr = 0U;
    uint8_t DateUnitSize = 0U;
    uint8_t RealLen = 0U;

    if ((0U == Data) || (EepSize <= Addr) || (EepSize < (Addr + Size)))
    {
        return EEP_STATU_ERROR;
    }

    Ret = Eep_Flash_UnlockCtrl();
    while ((Size > 0U) && (EEP_SUCCESS == Ret))
    {
        DateUnitSize = EepFlashDateByteNum;
        TempAddr = Addr - (Addr % EepFlashDateByteNum);
        RealLen = EepFlashDateByteNum - (Addr % EepFlashDateByteNum);
        if (Size <  RealLen)
        {
            DateUnitSize = Size;
            RealLen = Size;
        }

        /* if current write data with EEP data is the same (the lenght is the min FLASH write uint),
            if no ,will write data, else, will write data
        */
        for (i = 0; i < RealLen; i++)
        {
            if (Data[i] != *(uint8_t *)(Addr + EepRamBaseAddr + i))
            {
                break;
            }
        }

        if (i < DateUnitSize)
        {
            for (i = 0; i < RealLen; i++)
            {
                *(uint8_t *)(Addr + EepRamBaseAddr + i) = Data[i];
            }
            Ret = Eep_WriteExt((TempAddr + EepRamBaseAddr),
                               (uint8_t *)(TempAddr + EepRamBaseAddr), DateUnitSize);
        }
        /* Update destination address */
        Addr += RealLen;
        /* Update size */
        Size -= RealLen;
        /* Update data */
        Data += RealLen;
    }
    Eep_Flash_LockCtrl();

    return Ret;
}

/*!
 * @brief EEP read
 *
 * @param[in] addr: EEP read address
 * @param[in] data: Point to the buffer ready to read the data from EEP
 * @param[in] size: the number of read data(uint is byte)
 * @return EEP operate status
 */
Eep_StatusType Eep_Hal_Read(uint32_t Addr, uint8_t *Data, uint16_t Size)
{
    uint32_t i;

    if ((0U == Data) || (EepSize <= Addr) || (EepSize < (Addr + Size)))
    {
        return EEP_PARA_ERROR;
    }

    for (i = 0U; i < Size; i++)
    {
        /* check data effective */
        Data[i] = *(uint8_t *)(EepRamBaseAddr + Addr + i);
    }

    return EEP_SUCCESS;
}

/*!
 * @brief erase all EEP space
 *
 * @param[in] none
 * @return EEP operate status
 */
Eep_StatusType Eep_Hal_Erase(void)
{
    Eep_StatusType Ret = EEP_SUCCESS;
    uint16_t i;

    Ret = Eep_Flash_UnlockCtrl();
    if (EEP_SUCCESS == Ret)
    {
        for (i = 0U; i < EEP_GROUPS_NUM; i++)
        {
            /* erase eep space */
            Ret = Eep_Flash_VerifyGroup(EepFlashBaseAddr + i * EepGroupSize, EepGroupSize);
            if (EEP_SUCCESS != Ret)
            {
                Ret = Eep_Flash_EraseGroup(EepFlashBaseAddr + i * EepGroupSize, EepGroupSize);
            }
            if (EEP_SUCCESS != Ret)
            {
                break;
            }
        }
    }
    if (EEP_SUCCESS == Ret)
    {
        for (i = 0U; i < EepSize; i += 4U)
        {
            *(uint32_t *)(EepRamBaseAddr + i) = 0xFFFFFFFFU;
        }
    }
    Eep_Flash_LockCtrl();

    return Ret;
}

/*!
 * @brief EEP initialize
 *
 * @param[in] config: EEP parameter struct
 * @return EEP operate status
 */
Eep_StatusType Eep_Hal_Init(const Eep_ConfigType *Config)
{
    Eep_StatusType Ret = EEP_SUCCESS;
    uint16_t i;

    EepSize = Config->EepSize;
    if ((EepSize % 128U) || (EepSize > 4096U))
    {
        return EEP_STATU_ERROR;
    }

    EepFlashMinProByteNum = Config->FlashMinProByte;
    EepFlashDateByteNum = EepFlashMinProByteNum - 2U;
    EepFlashBaseAddr = Config->EepFlashBaseAddr;
    g_eepCallback = Config->CallbackType;
    EepGroupSize = EepSize * Config->FlashMinProByte;
    if (EepGroupSize < Config->FlashPageSize)
    {
        EepGroupSize = Config->FlashPageSize;
    }

    EepRamBaseAddr = Config->EepRamBaseAddr;
    for (i = 0U; i < EEP_GROUPS_NUM; i++)
    {
        EepGroupAddr[i][0U] = EepFlashBaseAddr + i * EepGroupSize;
        EepGroupAddr[i][1U] = EepFlashBaseAddr + (i + 1U) * EepGroupSize;
    }

    for (i = 0U; i < (EepFlashMinProByteNum >> 2U); i++)
    {
        EepGroupFlag[i] = EEP_GROUP_FLAG_VALUE;
    }

    Ret = Eep_Flash_PreInitCheck(EepRamBaseAddr, EepFlashBaseAddr);
    if (Ret != EEP_SUCCESS)
    {
        return EEP_PARA_ERROR;
    }

    Ret = Eep_Flash_UnlockCtrl();
    if (EEP_SUCCESS == Ret)
    {
        Ret = UpdateOperateAddr();
    }

    Eep_Flash_LockCtrl();

    return Ret;
}

/*!
 * @brief Get EEP lib version
 *
 * @param[in] EEP version struct
 * @return EEP operate status
 */
Eep_StatusType Eep_Hal_GetVersion(Eep_VersionType *Version)
{
    Eep_StatusType Ret = EEP_SUCCESS;

    if (Version)
    {
        Version->Main = 2U;
        Version->Sub = 1U;
        Version->Rev = 7U;
        Version->Year = 2024U;
        Version->Month = 4U;
        Version->Day = 3U;
    }
    else
    {
        Ret = EEP_PARA_ERROR;
    }

    return Ret;
}

/*!
 * @brief Reload flash data to eeprom
 *
 * @param[in] none
 * @return EEP operate status
 */
Eep_StatusType Eep_Hal_Refresh(void)
{
    Eep_StatusType Ret = EEP_SUCCESS;
    uint32_t TmpCurFlashOperatAddr;

    TmpCurFlashOperatAddr = CurFlashOperatAddr;
    memset((char *)EepRamBaseAddr, 0xff, EepSize);

    Ret = LoadFlashDataToSram(CurGroup, TmpCurFlashOperatAddr);

    return Ret;
}

/*!
 * @brief Check EEPROM current busy status
 *
 * @param[in] none
 * @return EEP current status busy or idle
 */
Eep_StatusType Eep_Hal_CheckBusy(void)
{
    Eep_StatusType Ret = EEP_SUCCESS;

    Ret = Eep_Flash_CheckBusy();

    return Ret;
}
/* =============================================  EOF  ============================================== */
